<template>
  <div>
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-tablec"
    >
      <el-table-column
        align="center"
        label="小程序AppID"
        prop="appId"
        min-width="180"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('appName')"
        prop="appName"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="小程序类型"
        prop="appType"
        min-width="100"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <span v-if="scope.row.appType == '0'">会员小程序</span>
          <span v-if="scope.row.appType == '1'">运营小程序</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="企业名称"
        prop="companyName"
        min-width="150"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="备案省份"
        prop="address"
        min-width="150"
        show-overflow-tooltip
      />
      <!-- <el-table-column
        align="center"
        label="单位性质"
        prop=""
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="证件类型"
        prop=""
        min-width="120"
        show-overflow-tooltip
      /> -->
      <el-table-column
        align="center"
        label="人脸核验状态"
        min-width="120"
        fixed="right"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <span v-if="scope.row.taskStatus == '1'">核验中</span>
          <span v-if="scope.row.taskStatus == '2'">核验失败</span>
          <span v-if="scope.row.taskStatus == '3'">核验成功</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="备案审核状态"
        prop="statusName"
        min-width="120"
        fixed="right"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('handle')"
        prop=""
        fixed="right"
        min-width="220"
      >
        <template v-slot="scope">
          <div class="flex-cc">
            <el-button
              v-if="
                scope.row.status == '1' ||
                scope.row.status == '2' ||
                scope.row.status == '4'
              "
              type="text"
              @click="handleEdit(scope.row)"
              >{{ translate("edit") }}</el-button
            >
            <el-button
              v-if="scope.row.taskStatus == '2'"
              type="text"
              @click="handleSub(scope.row)"
              >{{ translate("tj") }}</el-button
            >
            <el-button
              v-if="
                (scope.row.status == '1' ||
                  scope.row.status == '2' ||
                  scope.row.status == '4') &&
                scope.row.taskStatus == '3'
              "
              type="text"
              @click="handleBeian(scope.row)"
              >备案</el-button
            >
            <el-button
              v-if="scope.row.status != '2' && scope.row.taskStatus == '3'"
              type="text"
              @click="handleCheck(scope.row)"
              >审核记录</el-button
            >
            <el-button
              v-if="scope.row.status == '1' || scope.row.status == '2'"
              type="text"
              @click="handleDel(scope.row)"
              >{{ translate("del") }}</el-button
            >
            <el-button
              v-if="scope.row.status == '0'"
              type="text"
              @click="handleCancel(scope.row)"
              >撤销审核</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="审核记录" :visible.sync="isCheckRecord" width="1000px">
      <el-table
        :data="checkList"
        element-loading-text="Loading"
        border
        fit
        :header-row-class-name="'table-header'"
        class="doumee-element-table"
      >
        <!-- <el-table-column
          align="center"
          label="提交人"
          prop=""
          min-width="100"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="提交时间"
          prop="createTime"
          min-width="160"
          show-overflow-tooltip
        /> -->
        <el-table-column
          align="center"
          label="审核时间"
          prop="createTime"
          min-width="160"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="审核状态"
          prop="auditStatusName"
          min-width="140"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="拒绝理由"
          prop="auditInfo"
          min-width="360"
          show-overflow-tooltip
        >
          <template v-slot="scope">
            <el-popover
              placement="bottom"
              width="400"
              trigger="hover"
              :content="scope.row.auditInfo"
            >
              <el-button type="text" slot="reference">拒绝理由</el-button>
            </el-popover>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import {
  miniRecordAdminList,
  miniRecordAdminDel,
  miniRecordAdminApply,
  miniRecordAdminCancel,
  miniRecordAdminRecordList,
  miniRecordTaskVerify
} from '@/api'
export default {
  data() {
    return {
      meta: [],
      list: [],
      listLoading: false,
      filters: {},
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,

      isCheckRecord: false,
      checkList: []
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList()
  },
  activated() {
    this.$ref.table.doLayout()
  },
  methods: {
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      if (page) {
        pagination.page = page
      }
      miniRecordAdminList({
        pagination,
        param: { ...filters }
      })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode === '000000') {
            this.list = res.recordList
            this.total = res.totalCount
          }
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    handleSub(row) {
      this.listLoading = true
      miniRecordTaskVerify({ param: { appId: row.appId } }).then(res => {
        this.listLoading = false
        if (res.errorCode !== '000000') return
        this.$message.success(this.translate('tjScs'))
        this.getList()
      }, () => {
        this.listLoading = false
      })
    },
    handleEdit(row) {
      this.$router.push({
        name: 'RecordWeChatEdit',
        query: {
          appId: row.appId,
          appName: row.appName,
          isHasIcpInfo: row.isHasIcpInfo || '1',
          id: row.id
        }
      })
    },
    handleBeian(row) {
      this.listLoading = true
      miniRecordAdminApply({ param: { appId: row.appId } }).then(res => {
        this.listLoading = false
        if (res.errorCode !== '000000') return
        this.$message.success('备案成功')
        this.getList()
      }, () => {
        this.listLoading = false
      })
    },
    handleCheck(row) {
      miniRecordAdminRecordList({ param: { appId: row.appId } }).then(res => {
        if (res.errorCode !== '000000') return
        this.checkList = res.recordList || []
        this.isCheckRecord = true
      })
    },
    handleDel(row) {
      this.$confirm('是否删除该条备案？', this.translate('ts'), {
        confirmButtonText: this.translate('qd'),
        cancelButtonText: this.translate('cancel')
      }).then(() => {
        miniRecordAdminDel({ param: { id: row.id } }).then(res => {
          if (res.errorCode !== '000000') return
          this.$message.success(this.translate('delScs'))
          this.getList()
        })
      })
    },
    handleCancel(row) {
      this.listLoading = true
      miniRecordAdminCancel({ param: { appId: row.appId } }).then(res => {
        this.listLoading = false
        if (res.errorCode !== '000000') return
        this.$message.success('撤回备案成功')
        this.getList()
      }, () => {
        this.listLoading = false
      })
    }
  }
}
</script>

<style>
</style>
